﻿#pragma once

#include <QWidget>
#include <QCloseEvent>
#include "ui_OpenGLSpecialEffectsWindow.h"
#include <QString>
#include <thread>
#include <chrono>
#include <QDebug>
#include <QTimer>
#include "../../ffmpeg/format/YDemuxer.h"
#include "../../ffmpeg/format/YMuxer.h"
#include "../../ffmpeg/codec/VideoReScaler.h"
#include "../../ffmpeg/codec/YDecoder.h"
#include "../../ffmpeg/codec/YEncoder.h"
#include "../../ffmpeg/task/YTools.h"

class OpenGLSpecialEffectsWindow : public QWidget
{
	Q_OBJECT

public:
	void OnStartPlay();
	void Release();
	void setEffectsArgs(OpenGLEffects effect_type);
	void Reset();
	OpenGLSpecialEffectsWindow(QWidget* parent = nullptr);
	~OpenGLSpecialEffectsWindow();

protected:
	// 重写关闭事件处理函数
	void closeEvent(QCloseEvent* event) override;

signals:
	void updateUi(AVFrame* frame);

public slots:
	void onSelectedFile();
	void onStartPlayVideo();
	void OnUpdateUi(AVFrame* frame);
	void OnTimeout();

	void onEffectsChanged(int pos);

private:
	Ui::OpenGLSpecialEffectsWindow ui;
	QString filePath;
	std::unique_ptr<std::thread> renderThread;
	bool isRunning = false;
	YDemuxer* demuxer = nullptr;
	YDecoder* decoder = nullptr;
	VideoReScaler* videoReScaler = nullptr;
	std::mutex m_mutex;
	QTimer* timer = nullptr;
	YAVFrameList frameList;
};
